<?php
	session_start();
	function yzm($width=200,$height=50,$length=6,$img_type='png')
	{
		$img=imagecreatetruecolor($width, $height);
		$white=imagecolorallocate($img, 255, 255, 255);
		imagefill($img, 0, 0, $white);

		for ($i=0; $i <1000 ; $i++) 
		{ 
			imagesetpixel($img, mt_rand(0,$width), mt_rand(0,$height), imagecolorallocate($img,mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)));
		}

		for ($i=0; $i <10 ; $i++) 
		{ 
			imageline($img, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)));
		}
		$str=implode(range('a', 'z')).implode(range('A', 'Z')).implode(range(0, 9));
		$str=substr(str_shuffle($str), 0,$length);

		$_SESSION['vcode']=$str;

		$w=$width/$length;
		for ($i=0; $i <$length ; $i++) 
		{ 
			$x=20+$i*$w;
			$y=mt_rand(30,$height);
			$color=imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
			imagettftext($img, mt_rand(20,35), mt_rand(-30,30), $x, $y, $color, './font/'.mt_rand(1,7).'.ttf', $str[$i]);
		}

		if ($img_type=='jpg') 
		{
			$img_type='jpeg';
		}

		$func_img='image'.$img_type;
		$header="content-type:image/".$img_type;
		header($header);
		$func_img($img);

		imagedestroy($img);
	}
	yzm(200,50,4,'jpg');
?>